/**
 * @author of2198
 * @date 2017/4/27.
 * @description
 */

import { Actor, Action } from "iflux2";
import { Map, List, fromJS } from "immutable";

export default class PageManageActor extends Actor {
  defaultState() {
    return {
      pageList: List(), //页面列表
      totalCount: 0, //总条数
      pageSize: 10, //每页显示几条
      pageNo: 1, //当前页
      pageTypeInfo: Map(), //页面类型信息
      platformBtns: List(), //业务线的平台类型
      pageTypeBtns: List(), //业务线的页面类型
      templateCount: 0, //模板总条数
      templateList: List(), //模板列表
      domainList: List(), //域名信息
      activatedPageInfo: Map()
    };
  }

  @Action("SET_PLATFORM_BTN_LIST")
  setPlatformBtns(state, btnInfo) {
    return state.set("platformBtns", fromJS(btnInfo.platformTabInfo));
  }

  @Action("SET_PAGE_TYPE_BTN_LIST")
  setPageTypeBtns(state, btnInfo) {
    return state.set("pageTypeBtns", fromJS(btnInfo.pageTypeTabInfo));
  }

  @Action("SET_PAGE_LIST")
  setPageList(state, pageInfo) {
    return state
      .set("pageList", fromJS(pageInfo.pageInfoList))
      .set("totalCount", pageInfo.totalCount);
  }

  @Action("SET_PAGE_TYP_INFO")
  setPageTypeInfo(state, pageInfo) {
    return state.set("pageTypeInfo", fromJS(pageInfo));
  }

  @Action("SET_TEMPLATE_LIST")
  setTemplateList(state, templateInfo) {
    return state
      .set("templateList", fromJS(templateInfo.tplList))
      .set("templateCount", templateInfo.totalCount);
  }

  @Action("SET_DOMAIN_LIST")
  setDomainList(state, domainList) {
    return state.set("domainList", fromJS(domainList));
  }

  @Action("DELETE_PAGE_LIST_INDEX")
  deletePageByIndex(state, index) {
    return state
      .set("pageList", state.get("pageList").delete(index))
      .set("totalCount", state.get("totalCount") - 1);
  }

  @Action("SET_PAGE_NO")
  setPageNo(state, pageNo) {
    return state.set("pageNo", pageNo);
  }

  @Action("UPDATE_PAGE_TITLE")
  updatePageTitle(state, info) {
    return state.update("pageList", pageList => {
      return pageList.update(info.index, item => item.set("title", info.title));
    });
  }

  @Action("SET_ACTIVATED_PAGE_INFO")
  setActivatedPageInfo(state, activatedPage) {
    return state.set("activatedPageInfo", fromJS(activatedPage));
  }
}
